//
//  MapLocAddressView.m
//  carcareIOS
//
//  Created by 王然 on 16/6/30.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "MapLocAddressView.h"
@interface MapLocAddressView()
{
    //虚线起点位置
    CGPoint dottenLineStart;
    CGPoint dottenLineEnd;
}

@property (nonatomic , strong) UILabel * starLocL;//起点坐标

@property (nonatomic , strong) UILabel * endLocL;//终点坐标
@end
@implementation MapLocAddressView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self resetBorderWidth:0.5 borderColor:[Theme lineNewColor]];;
        
        CGFloat viewX = 33 * __MAIN_RATIO_375;
        CGFloat labelViewH = 45 * __MAIN_RATIO_375;
        CGFloat viewY =  ( self.height -  labelViewH - 5) / 2;
        CGFloat labelH = 20;
        CGFloat bottomLabelY = viewY + labelH + (labelViewH - labelH * 2) + 5;
        CGFloat cornerViewH = 5;
        UIView * startCornerView = [self cornerViewWithColor:COLOR_HEXSTRING(@"#43E6AF") withFrame:CGRectMake(viewX, viewY + (labelH - cornerViewH) / 2, cornerViewH, cornerViewH) onView:self];
        dottenLineStart = CGPointMake( viewX + cornerViewH / 2,  startCornerView.bottom + 1);
        CGFloat labelW = self.width - viewX * 2 - cornerViewH * 2 ;
        //[NSString stringWithFormat:@"起： %@",self.startLocStr]
        self.starLocL = [Factory labelWithFrame:CGRectMake(viewX + cornerViewH * 2, viewY, labelW, labelH) font:FONT_DEFAULT_Light(14  * __MAIN_RATIO_375) text:@"" textColor:[Theme wordColor] onView:self textAlignment:NSTextAlignmentLeft];
        
        UIView * endCornerView = [self cornerViewWithColor:[Theme orangeColor] withFrame:CGRectMake(viewX, bottomLabelY + (labelH - cornerViewH) / 2, cornerViewH, cornerViewH) onView:self];
        dottenLineEnd = CGPointMake(dottenLineStart.x, endCornerView.top - 1);
        
        //[NSString stringWithFormat:@"终： %@",self.endLocStr]
        self.endLocL = [Factory labelWithFrame:CGRectMake(self.starLocL.left, bottomLabelY, labelW, labelH) font:FONT_DEFAULT_Light(14  * __MAIN_RATIO_375) text:@"" textColor:[Theme wordColor] onView:self textAlignment:NSTextAlignmentLeft];
        [self setNeedsDisplay];
    }
    return self;
}
- (void)reloadStarLoc:(NSString *)startLoc withEndLoc:(NSString *)endLoc
{
    self.starLocL.text = [NSString stringWithFormat:@"起：%@",startLoc];
    self.endLocL.text = [NSString stringWithFormat:@"终：%@",endLoc];
}
#pragma mark - 创建小圆点  设置颜色
- (UIView *)cornerViewWithColor:(UIColor *)color withFrame:(CGRect)frame onView:(UIView *)superView
{
    UIView * cornerView = [[[UIView viewWithFrame:frame] resetBackgroundColor:color] setupOnView:superView];
    cornerView.layer.cornerRadius = cornerView.width / 2;
    cornerView.layer.masksToBounds = YES;
    return cornerView;
}
#pragma mark - 画虚线
- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextBeginPath(context);
    CGContextSetLineWidth(context, 1.0);
    CGContextSetStrokeColorWithColor(context, [Theme lineColor].CGColor);
    CGFloat lengths[] = {2 , 2 , 2, 2, 2 , 2 , 2, 2, 2, 2};
    CGContextSetLineDash(context, 0, lengths, 1);//跳过0个再画虚线
    CGContextMoveToPoint(context, dottenLineStart.x, dottenLineStart.y);
    CGContextAddLineToPoint(context, dottenLineEnd.x, dottenLineEnd.y);
    CGContextStrokePath(context);
    CGContextClosePath(context);
}
- (void)awakeFromNib {
    [super awakeFromNib];
    
}

@end
